-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Add citations #2657
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Add citations #2657
Conversation
Docs Preview
|
Hi! I've been looking into citation support for OpenRouter (related to #3126) and discovered something interesting while investigating the codebase. The OpenAI Chat Completions API actually has built-in support for citations through the ChatCompletionMessage.annotations: Optional[List[Annotation]]
└─ Annotation
├─ type: Literal['url_citation']
└─ url_citation: AnnotationURLCitation
├─ url: str
├─ title: str
├─ start_index: int
└─ end_index: int I noticed that the current implementation in Since providers like OpenRouter, Azure, Deepseek, Grok, Ollama, and others all use The implementation would be similar to what's already done for the Responses API (lines 799-810), though there's one consideration: when Would it make sense to include Chat Completions citation support in this PR, or should it be a follow-up? I'm happy to work on the implementation if that would be helpful. |
@certainly-param Thanks for looking into this, good to see that we can support this for OpenAI Chat Completions (and derivative APIs) as well, not just Responses. The biggest challenge in this PR is to land on a generic data representation for citations, that includes all the interesting info from OpenAI, Anthropic, and Google's citation representations. Especially Google does things quite differently, and we have to think about different types of citations/annotations, e.g. from web search, from file search, possibly provided by a tool call result... If you want to look into that, be my guest, but the OpenAI Chat Completions support is probably the easiest part of the puzzle :) |
google_search
tool grounding metadata available in model response #2890 (grounding_metadata
+citation_metadata
)